#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
    int dx[2] = { 0,1 };
    int dy[2] = { 1,0 };
    bool vis[101][101];
    int ret = 0;
    int m, n, k;
public:
    int wardrobeFinishing(int _m, int _n, int _cnt) {
        m = _m, n = _n, k = _cnt;
        dfs(0, 0);
        return ret;
    }
    void dfs(int i, int j)
    {
        vis[i][j] = true;
        ret++;
        for (int k = 0;k < 2;k++)
        {
            int x = i + dx[k], y = j + dy[k];
            if (x >= 0 && x < m && y >= 0 && y < n && !vis[x][y] && check(x, y))
            {
                dfs(x, y);
            }
        }
    }
    bool check(int x, int y)
    {
        int r = 0;
        while (x)
        {
            r += x % 10;
            x /= 10;
        }
        while (y)
        {
            r += y % 10;
            y /= 10;
        }
        return r <= k;
    }
};